class employee: def __init__(self,name,sal): self.name=name self.salary=sal emp=employee("Amit Jain",2000) print(emp.salary) emp.salary=3000 print(emp.salary)
2000 3000
class employee: def __init__(self,name,sal): self._name=name self._salary=sal emp=employee("Amit Jain",2000) print(emp._salary) emp._salary=3000 print(emp._salary)
2000 3000
class employee: def __init__(self,name,sal): self.__name=name self.__salary=sal emp=employee("Amit Jain",2000) print(emp.__salary) emp.__salary=3000 print(emp.__salary)
AttributeError: 'employee' object has no attribute '__salary'
class Box : def setDimension(self,x,y,z): self.L = x self.B = y self.H = z def volume(self): v = self.L*self.B*self.H print("Volume is",v) a = Box() b = Box() a.setDimension(2,3,4) b.setDimension(4,5,3) a.volume() b.volume()
Volume is 24 Volume is 60
class Rectangle : def setDimension(self,x,y): self.length = x self.breadth = y def area(self): a=self.length*self.breadth print("Area is ",a) def perimeter(self): p=2*(self.length+self.breadth ) print("Perimeter is ",p) a = Rectangle() b = Rectangle() a.setDimension(5,7) b.setDimension(10,20) a.area() a.perimeter()
Area is 35 Perimeter is 24 Area is 200
class circle : def setradius(this,n): this.R = n def area(this): a =3.14*this.R**2 print("Area is ",a) def circumference(this): c =2*3.14*this.R print("Circumference is ",c) a = circle() b = circle() a.setradius(5) b.setradius(2) a.area() b.area() b.circumference()
Area is 78.5 Area is 12.56 Circumference is 12.5
class worker: def setData(self,n,w,d): self.name=n self.wages=w self.wdays=d def showData(self): print("Name is ",self.name) print("Wages is ",self.wages) print("Wdays is ",self.wdays) def payment(self): p=self.wages*self.wdays print("Payment is ",p) a=worker() b=worker() a.setData("Raja",500,5) b.setData("Gaja",400,8) a.showData() a.payment() b.showData() b.payment()
Name is Raja Wages is 500 Wdays are 5 Payment is 2500 Name is Gaja Wages is 400 Wdays are 8 Payment is 3200
class Set: def setData(self,x,y,z): self.n1=x self.n2=y self.n3=z def sum(self): s=self.n1+self.n2+self.n3 print("sum is ",s) def mean(self): s=self.n1+self.n2+self.n3 m=s/3 print("Mean is ",m) a=Set() b=Set() a.setData(2,5,3) b.setData(6,10,4) a.sum() b.sum() b.mean()
Sum is 10 Sum is 20 Mean is 6.6666667